import Dict from './Dict.ts'

import { mergeOptions } from './DictOptions.ts'
import { App } from 'vue'

export default function (app: App, options: any) {
  console.log('dictData')
  /*将这个options与DictOptions中options的数据进行合并*/
  mergeOptions(options)
  /*做一个全局混入，每个组件上队徽挂载data中的数据*/
  app.mixin({
    data() {
      /*传递进来的值不能为空---传递进来的值就是要查找的type*/
      if (
        this.$options === undefined ||
        this.$options.dicts === undefined ||
        this.$options.dicts === null
      ) {
        return {}
      }
      /*通过new的方式来创建对象*/
      const dict = new Dict()
      return {
        dict,
      }
    },
    created() {
      if (!(this.dict instanceof Dict)) {
        return
      }
      /*调用init方法进行初始化*/
      this.dict.init(this.$options.dicts)
    },
  })
}
